server = Server('127.0.0.1',8060);
access = server.getServiceAccess();
list_ms = access.getModelServiceList();
for index = 1: numel(list_ms)
    disp(['ID : ',list_ms(index).id,' - Name : ',list_ms(index).name,' - Type : ',list_ms(index).type])
end
dataid = access.uploadDataByFile('E:\NativeTest\TestData\TouchAir\input.xml','input.xml');
if ~(strcmp(dataid,''))
    disp(['TouchAir - Data ID : ',dataid]);
    % invoke model
    touchair = access.getModelServiceByID('5aab9a194290c617a88f347b');
    pDataconfig = access.createDataConfigurationItem('aa00cced-60e7-48a5-90d2-f91ac08b624d','InputData',dataid);
    recordid = touchair.invoke(pDataconfig);
    disp(['Invoke successfully! Model service Record ID is : [',recordid,']']);
    record = access.getModelServiceRunningRecordByID(recordid);
    % record.waitForFinished();
    msrstatus = record.getStatus().status;
    while msrstatus == 0
        record.refresh();
        list_logs = record.getLogs();
        for index = 1:numel(list_logs)
            logs = list_logs(index);
            disp([logs.type,' - ',logs.state, ' - ',logs.event,' - ',logs.message]);
        end
        msrstatus = record.getStatus().status;
    end
    disp('TouchAir model has been finished')
    for index = 1:numel(record.output)
        item = record.output(index);
        dat = access.getDataByID(item.dataid);
        % get file ext 
        % maybe use [filepath,name,ext] = fileparts(filename)
        datavalue = dat.value;
        [filename,name,ext] = fileparts(datavalue);
        % save as file
        dat.save(['E:\NativeTest\TestData\TouchAir\',item.eventname,ext]);
    end
else
    disp('upload data file failed');
end
